/**
 * 随机产生0至n-1的整数
 */
export const randomInt = n => {
  return Math.floor(Math.random() * n)
}

/**
 * 产生一个随机的Message对象
 */
export const getRandomMessage = (systemName, subSystemName) => {
  let message = {}
  for (let deviceId = 1; deviceId <= 3; deviceId++) {
    for (let i = 1; i <= 4; i++) {
      let k = systemName + '.' + subSystemName + '.' + 'Device_' + deviceId + '.' + 'Int_Point_' + i
      message[k] = randomInt(10)
    }
    for (let i = 1; i <= 2; i++) {
      let k = systemName + '.' + subSystemName + '.' + 'Device_' + deviceId + '.' + 'Boolean_Point_' + i
      message[k] = Math.random() > 0.5
    }
    for (let i = 1; i <= 2; i++) {
      let k = systemName + '.' + subSystemName + '.' + 'Device_' + deviceId + '.' + 'Double_Point_' + i
      message[k] = Number((Math.random() * 100).toFixed(4))
    }
  }
  return message
}

/**
 * 对一个数值,进行微调,并返回调整后的值
 */
export const adjustNumber = num => {
  if (Math.abs(num % 1) > 0.0001) { // 小数(调整范围±0.5,带有2位小数点)
    return num + (randomInt(101) - 50) * 0.01
  } else { // 整数(调整范围为±5)
    return num + randomInt(11) - 5
  }
}
